﻿using System;
using Object = UnityEngine.Object;

namespace ZFramework.Runtime
{
    /// <summary>
    /// 使用asset loader加载资源成功事件
    /// </summary>
    public sealed class AssetLoadSuccessEventArgs : GameEventArgs
    {
        public static int EventId = typeof(AssetLoadSuccessEventArgs).GetHashCode();

        /// <summary>
        /// 初始化
        /// </summary>
        public AssetLoadSuccessEventArgs()
        {
            Asset = null;
            Path = String.Empty;
        }

        /// <summary>
        /// 获取资源
        /// </summary>
        public Object Asset { get; private set; }

        /// <summary>
        /// 获取资源路径
        /// </summary>
        public string Path { get; private set; }


        /// <summary>
        /// asset加载成功
        /// </summary>
        /// <param name="asset">加载的资源。</param>
        /// <param name="path">资源路径。</param>
        public static AssetLoadSuccessEventArgs Create(Object asset, string path)
        {
            AssetLoadSuccessEventArgs assetLoadSuccessEventArgs = ReferencePool.Acquire<AssetLoadSuccessEventArgs>();
            assetLoadSuccessEventArgs.Asset = asset;
            assetLoadSuccessEventArgs.Path = path;
            return assetLoadSuccessEventArgs;
        }

        public override int Id
        {
            get { return EventId; }
        }

        /// <summary>
        /// 清理
        /// </summary>
        public override void Clear()
        {
            Asset = null;
            Path = String.Empty;
        }
    }
}

